package com.lenovo.smarttraffic;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.Button;
import android.widget.LinearLayout;

import com.lenovo.smarttraffic.ui.activity.BaseActivity;
import com.lenovo.smarttraffic.util.ToastUtils;

import butterknife.BindView;

public class SettingsActivity extends BaseActivity {

    @BindView(R.id.find_etc_info)
    LinearLayout find_etc_info;

    @BindView(R.id.user_sign)
    LinearLayout user_sign;

    @BindView(R.id.find_etc_history)
    LinearLayout find_etc_history;

    @BindView(R.id.version)
    LinearLayout version;

    @BindView(R.id.login_out)
    Button login_out;

    @Override
    protected int getLayout() {
        return R.layout.activity_settings;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initToolBar(this, "设置");

        SharedPreferences sharedPreferences = getSharedPreferences(Constant.LOGIN_INFO, MODE_PRIVATE);
        String loginInfo = sharedPreferences.getString(Constant.LOGIN_INFO, null);

        if (loginInfo == null) {
            login_out.setEnabled(false);
        }

        login_out.setOnClickListener(v -> {
            if (loginInfo == null) {
                ToastUtils.showToast(this, "未登录");
            } else {
                sharedPreferences.edit().putString(Constant.LOGIN_INFO, null).apply();
                ToastUtils.showToast(this, "退出登录成功");
            }
        });
    }


}
